<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;

class OrderController extends Controller
{
    //
    // public function index()
    // {
    // 	return view("home.order");
    // }
    public function index(Request $request)
    {
    	$where = [];
        $uid = session()->get("homeuser")->userid;
    	$db = DB::table("distribution")->where("uid",$uid);
    	if($request->has("name")){
    		$name = $request->input("name");
    		//添加where模糊匹配条件
    		$db->where("name","like","%{$name}%");
    		$where['name'] = $name;
    	}
    	
    	$list = $db->paginate(3);
    	// dd($list);
    	return view("home.order",["list"=>$list,"where"=>$where]);
    }
    public function destroy($id)
    {
        session(["dd"=>$id]);
        DB::table("distribution")->where("id",$id)->delete();
        return redirect('home/order');
    }
    
}
